﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Gozib.Web.Models.Bus;

namespace Gozib.Web.Controllers
{
    public class BusController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Result()
        {
            var queryString = Request.QueryString["t"];
            if (!String.IsNullOrWhiteSpace(queryString))
            {
                var values = queryString.Split('~');
                if (values.Length == 3)
                {
                    ViewBag.Message = String.Format("{0} - {1} on {2}", values[0], values[1], values[2]);
                }
                else
                {
                    ViewBag.Message = "Result not found!";
                }
            }

            return View();
        }

        [HttpPost]
        public ActionResult Result(BusBookingInfo bookingInfo)
        {
            TempData["b"] = bookingInfo;
            if (Request.IsAjaxRequest())
            {
                return Json(new { redirectToUrl = Url.Action("Booking") });
            }

            return View();
        }

        public ActionResult Booking()
        {
            var bookingInfo = TempData["b"] as BusBookingInfo;
            //if (bookingInfo == null) ; //TODO: Show the error page

            //TODO: Get Service Fee
            bookingInfo.ServiceFee = 5;
            bookingInfo.GrandTotal = (bookingInfo.FareTotal + bookingInfo.ServiceFee) - bookingInfo.Discount;

            return View(bookingInfo);
        }

        [HttpPost]
        public ActionResult Booking(BusBookingInfo bookingInfo)
        {
            //TODO
            return View(bookingInfo);
        }

        public ActionResult CancelTicket()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CancelTicket(string pnrOrBookingNumber)
        {
            return View();
        }
    }
}
